Skip to content

[FIX] Fix unit test failure on local machine in BookieSocketAddressTest.#4711

Open
Jason918 wants to merge 1 commit intoapache:masterfrom
Jason918:fix-bookie-test-mock
Open

[FIX] Fix unit test failure on local machine in BookieSocketAddressTest.#4711
Jason918 wants to merge 1 commit intoapache:masterfrom
Jason918:fix-bookie-test-mock

Conversation

@Jason918
Copy link
Contributor

@Jason918 Jason918 commented Feb 5, 2026

Descriptions of the changes in this PR:

Motivation

The unit tests in BookieSocketAddressTest were dependent on local system network configuration, particularly the use of loopback addresses (127.0.0.1). This caused inconsistent test behavior across different environments and could lead to test failures when loopback addresses were restricted by system configuration.

Changes

  • Added mockHostnameIPSetup helper method using Mockito.mockStatic to simulate DNS.getDefaultIP behavior
  • Modified testBookieAddressIsIPAddressByDefault to use mock instead of actual loopback addresses
  • Modified testBookieAddressIsHostname to use mock with resolvable localhost address
  • Simplified testAdvertisedWithNonLoopbackAddress by removing complex local network detection logic
  • All tests now use consistent mock approach instead of relying on actual network configuration

Key improvements:

  • Eliminates dependency on local system network settings
  • Ensures consistent test behavior across all environments
  • Improves test reliability and portability
  • Maintains all existing test assertions and functionality

Verification:

  • All 4 existing tests pass with the mock implementation
  • No regression in test coverage or functionality
  • Tests are now environment-agnostic

…al system configuration

- Replace direct network calls with Mockito mocks in BookieSocketAddressTest
- Add mockHostnameIPSetup helper method to simulate DNS.getDefaultIP behavior
- Remove dependency on actual network configuration and loopback addresses
- Ensure consistent test behavior across different environments
- All 4 existing tests pass with the mock implementation
Copy link

@zjxxzjwang zjxxzjwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

down

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants